/*
 * @Description: 
 * @Author: mmzhang
 * @Date: 2021-11-15 15:57:36
 * @LastEditTime: 2022-11-04 10:24:12
 */
import userApi from '@/config/server/api/user'
import biApi from '@/config/server/api/bi'
import customerApi from '@/config/server/api/customer'
import baseApi from '@/config/server/api/base.js'
import marketingApi from '@/config/server/api/marketing'
import tool from "@/common/tool.js"

// 首页成员积分
function getUserScoreList(params) {
  return userApi.homeScore.userScoreList.fetch(params).then(res => {
    res.records.forEach(item => {
      item.monthZeroCount = item.zeroCount
    })
    return res
  })
}

// 导出
function exportUserScoreList(info) {
  return userApi.homeScore.exportUserScoreList.fetch(info)
}

// 一键销分
function batchRemoveScore(params) {
  return userApi.homeScore.batchRemoveScore.fetch(params).then(res => {
    return res
  })
}

// 一键加分
function systemAddScore(params) {
  return userApi.homeScore.systemAddScore.fetch(params).then(res => {
    return res
  })
}

// 顾问销分
function removeScore(params) {
  return userApi.homeScore.removeScore.fetch(params).then(res => {
    return res
  })
}

// 积分明细
function userScoreDetailsList(params) {
  return userApi.homeScore.userScoreDetailsList.fetch(params).then(res => {
    return res
  })
}

function scoreUserHome(params) {
  return userApi.homeScore.scoreUserHome.fetch(params).then(res => {
    return res
  })
}

// 积分明细导出
function userScoreDetailsExport(params) {
  return userApi.homeScore.userScoreDetailsExport.fetch(params)
}

function scoreTypeList(params) {
  return userApi.homeScore.scoreTypeList.fetch(params).then(res => {
    let scoreTypeArr = []
    for (let i in res) {
      if (i != 12 && i != 13) { //去除加分项
        scoreTypeArr.push({
          key: i,
          value: res[i]
        })
      }
    }
    return scoreTypeArr
  })
}


// 案场积分表
function buildingScoreList(params) {
  if (params.showTab == 'personScore') {
    return biApi.integral.buildingScoreList.fetch(params).then(res => {
      return res
    })
  } else if (params.showTab == 'buildScore') {
    return biApi.integral.buildingList.fetch(params).then(res => {
      return res
    })
  } else {
    return biApi.integral.companyList.fetch(params).then(res => {
      return res
    })
  }
}

// 案场积分表统计信息
function buildingScoreCount(params) {
  if (params.showTab == 'personScore') {
    return biApi.integral.buildingScoreCount.fetch(params).then(res => {
      return res
    })
  } else if (params.showTab == 'buildScore') {
    return biApi.integral.buildingListCount.fetch(params).then(res => {
      return res
    })
  } else {
    return biApi.integral.companyListCount.fetch(params).then(res => {
      return res
    })
  }
}

// 导出
function integralExportFun(params) {
  if (params.showTab == 'taskImple') {
    if (params.checkIndex == 0) {
      return biApi.buildingScore.taskListUserExport.fetch(params)
    } else {
      return biApi.buildingScore.taskListBuildingExport.fetch(params)
    }
  } else if (params.showTab == 'personScore') {
    return biApi.integral.peopleListExport.fetch(params)
  } else if (params.showTab == 'buildScore') {
    return biApi.integral.buildingListExport.fetch(params)
  } else {
    return biApi.integral.companyListExport.fetch(params)
  }
}

// 导出成员积分
function buildingScoreExport(info) {
  return biApi.integral.buildingScoreExport.fetch(info)
}

// 导出积分明细
function buildingScoreDetailExport(info) {
  return biApi.integral.buildingScoreDetailExport.fetch(info)
}

function getSomeRoles() {
  return userApi.getSomeRoles.fetch().then(res => {
    res.forEach(element => {
      element.key = element.roleId
      element.value = element.roleName
    });
    return res
  })
}

function getAllRole() {
  return userApi.getAllRole.fetch().then(res => {
    res.forEach(element => {
      element.key = element.roleId
      element.value = element.roleName
    });
    return res
  })
}

// 0分申诉
function getZeroList(params) {
  return biApi.integral.zeroList.fetch(params).then(res => {
    return res
  })
}

// 导出
function zeroListExport(info) {
  return biApi.integral.zeroListExport.fetch(info)
}

function getAppealDetail(info) {
  return userApi.homeScore.appealDetail.fetch(info).then(res => {
    return res
  })
}

function submitAudit(info) {
  return baseApi.processAudit.audit.fetch(info).then(res => {
    return res
  })
}

function getIsAuditAuth(info) {
  return baseApi.processAudit.isAuditAuth.fetch(info).then(res => {
    return res
  })
}

// 案场积分导出 选项
function getExportOption(info) {
  return biApi.buildingScore.exportOption.fetch(info).then(res => {
    res.forEach(item => {
      [item.key, item.value] = [item.value, item.key]
    })
    return res
  })
}

// 批注任务明细

function getScoreTaskList(info) {
  return customerApi.task.scoreTaskList.fetch(info).then(res => {
    return res
  })
}

// 短文章明细
function getFindShortArticleByIds(info) {
  return marketingApi.shortSrticle.findShortArticleByIds.fetch(info).then(res => {
    return res
  })
}

// 任务执行
function getTaskCount(params) {
  return biApi.buildingScore.taskCount.fetch(params).then(res => {
    return res
  })
}

function getTaskList(params) {
  if (params.checkIndex == 0) {
    return biApi.buildingScore.taskListUser.fetch(params).then(res => {
      return res
    })
  } else {
    return biApi.buildingScore.taskListBuilding.fetch(params).then(res => {
      return res
    })
  }
}

export default {
  getUserScoreList,
  exportUserScoreList,
  batchRemoveScore,
  systemAddScore,
  removeScore,
  scoreUserHome,
  userScoreDetailsList,
  userScoreDetailsExport,
  scoreTypeList,
  buildingScoreList,
  buildingScoreCount,
  integralExportFun,
  buildingScoreExport,
  buildingScoreDetailExport,
  getSomeRoles,
  getAllRole,
  getZeroList,
  zeroListExport,
  getAppealDetail,
  submitAudit,
  getIsAuditAuth,
  getExportOption,
  getScoreTaskList,
  getFindShortArticleByIds,
  getTaskCount,
  getTaskList
}